package tcln.sors.model.product.dom;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import tcln.sors.model.base.dom.AbstractSorsNamedEntity;
import tcln.sors.model.core.type.CurrencyAmount;

/**
 * @author Truong Chau Lien Ngoc (lienngoc@gmail.com)
 */
@Entity
@Table(name = "TBL_PRODUCT")
@AttributeOverrides({ @AttributeOverride(name = "id", column = @Column(name = "PRODUCT_ID")) })
public class Product extends AbstractSorsNamedEntity {
    private static final long serialVersionUID = 1L;

    private ProductSpecification productSpecification;
    private Integer producedQuantity;
    private CurrencyAmount unitPrice; // in m2

    /**
     * Returns current value of {@link #productSpecification}.
     * 
     * @return the {@link #productSpecification}.
     */
    @ManyToOne(cascade = { CascadeType.ALL })
    @JoinColumn(name = "PRODUCT_SPEC_ID")
    public ProductSpecification getProductSpecification() {
        return productSpecification;
    }

    /**
     * Sets new value for {@link #productSpecification}.
     * 
     * @param productSpecification
     *            the new productSpecification to set
     */
    public void setProductSpecification(ProductSpecification productSpecification) {
        this.productSpecification = productSpecification;
    }

    /**
     * Returns current value of {@link #producedQuantity}.
     * 
     * @return the {@link #producedQuantity}.
     */
    @Column(name = "PRODUCED_QUANTITY")
    public Integer getProducedQuantity() {
        return producedQuantity;
    }

    /**
     * Sets new value for {@link #producedQuantity}.
     * 
     * @param producedQuantity
     *            the new producedQuantity to set
     */
    public void setProducedQuantity(Integer producedQuantity) {
        this.producedQuantity = producedQuantity;
    }

    /**
     * Returns current value of {@link #unitPrice}.
     * 
     * @return the {@link #unitPrice}.
     */
    @Embedded
    @AttributeOverrides({ @AttributeOverride(name = "amount", column = @Column(name = "UNIT_PRICE")),
            @AttributeOverride(name = "currencyCode", column = @Column(name = "UNIT_PRICE_CUR")) })
    public CurrencyAmount getUnitPrice() {
        return unitPrice;
    }

    /**
     * Sets new value for {@link #unitPrice}.
     * 
     * @param unitPrice
     *            the new unitPrice to set
     */
    public void setUnitPrice(CurrencyAmount unitPrice) {
        this.unitPrice = unitPrice;
    }
}
